window.onload=function(){
    linkto();
    let registerNow=document.querySelector('.registerNow');
    let name=document.querySelector('#name');
    let pwd=document.querySelector('#pwd');
    let pwd1=document.querySelector('#pwd1');
    let tell=document.querySelector('#tell');
    let captcha=document.querySelector('#captcha');
    let tellCaptcha=document.querySelector('#tellCaptcha');
    let msgoutBox=document.querySelector('.msgoutBox');
    let close=document.querySelector('.close');
    let timer;
    let msgSpan=document.querySelector('.msg span');
    

    // 定义正则
    let nameReg=/^[a-zA-Z0-9_-]{4,16}$/;
    let pwdReg = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
    let tellReg = /^1[3-9][0-9]{9}$/;
    let captchaReg = /^([0-9]|[a-z]|[A-Z]){4}$/;

// 立即注册按钮 点击 事件监听
registerNow.addEventListener('click',function(){
    // 非空验证 通过则跳转到登录页

    if(name.value&&pwd.value&&pwd1.value&&tell.value&&captcha.value&&tellCaptcha.value){
        // 正则验证
        if(!nameReg.test(name.value)){
            alert('用户名错误')
        }else if(!pwdReg.test(pwd.value)){
            alert('密码类型错误')
        }else if(!tellReg.test(tell.value)){
            alert('手机号输入错误')
        }else if(!captchaReg.test(captcha.value)){
            alert('验证码错误')
        }else if(!captchaReg.test(tellCaptcha.value)){
            alert('手机验证码错误')
        }else if(pwd.value!=pwd1.value){
            alert('两次密码输入不一致')
        }else{
            // 蒙层
            msgoutBox.style.display='block';
            // 定时器输出秒数
            let num=2;
              timer1=setInterval(function(){
                num--;
                msgSpan.innerText=num;
                if(num==0){
                    clearInterval(timer1)
                }
             },1000)
            //延时器控制跳转
            timer= setTimeout(function(){
                msgoutBox.style.display='none';                
                location.href='./login.html'
            },2000);
            
          
        }
    }else{
        alert('请填写完整信息！')
    }
})
// 关闭按钮点击事件 监听
close.addEventListener('click',function(){
    msgoutBox.style.display='none';
    clearTimeout(timer);
    clearInterval(timer1);
})


}